<h1>Expressions, Statements and Simple Statements</h1>

<p>
This article will introduce expressions and statements in Go.
</p>

<p>
Simply speaking, an expression represents a value and a statement represents an operation.
However, in fact, some special expressions may be composed of and represent several values,
and some statements may be composed of several sub operations/statements.
By context, some statements can be also viewed as expressions.
</p>

<p>
Simple statements are some special statements.
In Go, some portions of all kinds of control flows must be
simple statements, and some portions must be expressions.
Control flows will be introduced in the next Go 101 article.
</p>

<p>
This article will not make accurate definitions for expressions and statements.
It is hard to achieve this.
This article will only list some expression and statement cases.
Not all kinds of expressions and statements will be covered in this article,
but all kinds of simple statements will be listed.
</p>

<a class="anchor" id="expressions"></a>
<h3>Some Expression Cases</h3>

<p>
Most expressions in Go are single-value expressions.
Each of them represents one value. Other expressions represent multiple values
and they are named multi-value expressions.
</p>

<p>
In the scope of this document, when an expression is mentioned, we mean it is
a single-value expression, unless otherwise specified.
</p>

<p>
Value literals, variables, and named constants are all single-value expressions,
also called elementary expressions.
</p>

<p>
Operations (without the assignment parts) using the operators introduced in
the article <a href="operators.html">common operators</a> are all single-value expressions.
</p>

<p>
If a function returns at least one result, then its calls (without the
assignment parts) are expressions. In particular, if a function returns more
than one results, then its calls belong to multi-value expressions. Calls to
functions without results are not expressions.
</p>

<p>
Methods can be viewed as special functions.
So the aforementioned function cases also apply to methods.
Methods will be explained in detail in the article
<a href="method.html">method in Go</a> later.
</p>

<p>
In fact, later we will learn that custom functions, including methods,
are all function values, so they are also (single-value) expressions.
We will learn more about <a href="function.html">function types and values</a> later.
</p>

<p>
Channel receive operations (without the assignment parts) are also expressions.
Channel operations will be explained in the article
<a href="channel.html">channels in Go</a> later.
</p>

<p>
Some expressions in Go, including channel receive operations, may have optional results in Go.
Such expressions can present as both single-value and multi-value expressions, depending on different contexts.
We can learn such expressions in other Go 101 articles later.
</p>

<a class="anchor" id="simple-statements"></a>
<h3>Simple Statement Cases</h3>

<div>
There are six kinds of simple statements.

<ol>
<li>
	short variable declaration forms
</li>
<li>
	pure value assignments (not mixing with variable declarations),
	including <code>x op= y</code> operations.
</li>
<li>
	function/method calls and channel receive operations.
	As mentioned in the last section, these simple statements can also be used as expressions.
</li>
<li>
	channel send operations.
</li>
<li>
	nothing (a.k.a., blank statements).
	We will learn some uses of blank statements in the next article.
</li>
<li>
	<code>x++</code> and <code>x--</code>.
</li>
</ol>

<p>
Again, channel receive and sent operations will be introduced in the article
<a href="channel.html">channels in Go</a>.
</p>

<p>
Note, <code>x++</code> and <code>x--</code> can't be used as expressions.
And Go doesn't support the <code>++x</code> and <code>--x</code> syntax forms.
</p>

</div>

<h3>Some Non-Simple Statement Cases</h3>

<div>
An incomplete non-simple statements list:

<ul>
<li>
	standard variable declaration forms.
	Yes, short variable declarations are simple statements,
	but standard ones are not.
</li>
<li>
	named constant declarations.
</li>
<li>
	custom type declarations.
</li>
<li>
	package import declarations.
</li>
<li>
	explicit code blocks.
	An explicit code block starts with a <code>{</code> and ends with a <code>}</code>.
	A code block may contain many sub-statements.
</li>
<li>
	function declarations.
	A function declaration may contain many sub-statements.
</li>
<li>
	control flows and code execution jumps.
	Please read <a href="control-flows.html">the next article</a> for details.
</li>
<li>
	<code>return</code> lines in function declarations.
</li>
<li>
	deferred function calls and goroutine creations.
	The two will be introduced in <a href="control-flows-more.html">the article after next</a>.
</li>
</ul>

</div>

<h3>Examples of Expressions and Statements</h3>

<div>

<pre class="line-numbers"><code class="language-go">// Some non-simple statements.
import "time"
var a = 123
const B = "Go"
type Choice bool
func f() int {
	for a < 10 {
		break
	}

	// This is an explicit code block.
	{
		// ...
	}
	return 567
}

// Some simple statements:
c := make(chan bool) // channels will be explained later
a = 789
a += 5
a = f() // here f() is used as an expression
a++
a--
c <- true // a channel send operation
z := <-c  // a channel receive operation used as the
          // source value in an assignment statement.

// Some expressions:
123
true
B
B + " language"
a - 789
a > 0 // an untyped boolean value
f     // a function value of type "func ()"

// The following ones can be used as both
// simple statemetns and expressions.
f()
<-c // a channel receive operation
</code></pre>

<p>
</p>

</div>
